<include file="public@mobileHeader"/>
<section class="ui-container homework">


    <div class="ui-row ui-whitespace">
        <h1>布置作业</h1>
    </div>
    <form action="{:url('Homework/addPost')}" method="post">
        <div class="ui-form-item ui-border-b">
            <label>
                选择老师:
            </label>
            <div class="ui-select">
                <select name="teacher_id" id="teacher_id_id">
                    <option>选择老师</option>
                    <foreach name="all_teacher" item="vo">
                        <option value="{$vo.id}">{$vo.user_login}</option>
                    </foreach>
                </select>
            </div>
        </div>
        <div class="ui-form-item ui-border-b">
            <label>
                选择班级:
            </label>
            <div class="ui-select">
                <select class="class_id" name="class_id" id="class_id_id">
                    <option value="">选择班级</option>
                    <if condition="$role_id!=4">
                        </foreach>
                        <else/>
                        <foreach name="class_all" item="vo">
                            <if condition="isset($param.class) && $param.class == $vo.id ">
                                <option value="{$vo.id}" selected>
                                    {$vo.name}
                                </option>
                                <else/>
                                <option value="{$vo.id}">
                                    {$vo.name}
                                </option>
                            </if>
                        </foreach>
                    </if>
                </select>
            </div>
        </div>
        <div class="ui-form-item ui-border-b">
            <label>
                课次:
            </label>
            <input type="number" name="progress" placeholder="请输入课次">

        </div>
        <div class="ui-form-item ui-form-item-textarea ui-border-b">
            <label>
                上课进度:
            </label>
            <textarea name="lesson_theme" placeholder="请输入上课进度"></textarea>
        </div>
        <div class="ui-form-item ui-form-item-textarea ui-border-b">
            <label>
                作业内容:
            </label>
            <textarea name="content" placeholder="请输入上课内容"></textarea>
        </div>
        <div class="ui-btn-wrap">
            <button class="ui-btn-lg ui-btn-primary" id="addbtn">
                提交
            </button>
        </div>
    </form>
</section>
<include file="public@mobileFooter"/>
<script type="text/javascript">
    $(function () {
        $('body').on('change', '.class_id', function () {
            $id = $(this).find('option').not(function () {
                return !this.selected
            }).val();
            $_this = $(this);
            $.ajax({
                'url': "{:url('Homework/changProgress')}",
                'data': {'id': $id},
                'success': function (data) {
                    data = eval('(' + data + ')');
                    $("#progress").val(data.progress);
                    $("#progressedit").val(data.progress);
                },
                'error': function () {
                }
            })
        });

        $('body').on('change', '#teacher_id_id', function () {
            $id = $(this).find('option').not(function () {
                return !this.selected
            }).val();
            $.ajax({
                'url': "{:url('Homework/changeLesson')}",
                'data': {'id': $id},
                'success': function (data) {
                    data = eval('(' + data + ')');
                    $("#class_id_id").empty();
                    $("<option>选择班级</optioin>").appendTo($("#class_id_id"));
                    for (var i = 0; i < data.length; i++) {
                        $("<option value='" + data[i].id + "'>" + data[i].name + "</optioin>").appendTo($("#class_id_id"));
                    }
                },
                'error': function () {
                }
            })
        });
    });


//    $("form").submit(function () {
//        var url = $(this).attr("action");
//        $.post(url, function (data) {
//            data=$.parseJSON(data);
//            console.log(data);
//            if (data.code == 1) {
//                var el = $.tips({
//                    content: data.msg,
//                    stayTime: 2000,
//                    type: "success"
//                });
//            }else{
//                var el = $.tips({
//                    content: data.msg,
//                    stayTime: 2000,
//                    type: "warn"
//                });
//            }
//        });
//    });

</script>